﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WastedMechanics.CharState
{
    class CharStateHitM1H: CharStateSimpleAction
    {
        SelectableObject Target;        

        public CharStateHitM1H(Character chr, SelectableObject target)
            : base(chr)
        {
            ActionTime = 0.9f;
            AnimationName = "M1HHit1";
            Target = target;
        }

        public override void Enter()
        {
            Engine.SoundManager.SoundEffects["m1hswing.wav"].PlayNewInstance()
                .SetPosition(Character.Position);
            base.Enter();
        }

        public override void ActionPerform()
        {
            if (Target != null)
            {
                if (Target is Character)
                {
                    if ((Target.Position - Character.Position).Length < 1 
                        && (Mogre.Math.Abs(Character.LookDirection.DotProduct((Target.Position - Character.Position).NormalisedCopy)) > 0.6f)
                        )
                    {
                        (Target as Character).ReceiveDamage(Character.M1HWeapon.Damage, Character);
                        Engine.SoundManager.SoundEffects["meathit" + (Helper.RandomInt(3) + 1).ToString() + ".wav"].PlayNewInstance()
                            .SetPosition(Character.Position);
                    }                    
                }
            }
        }

        public override CharState GetNextState()
        {
            return new CharStateIdleM1H(Character);
        }
    }
}
